package GreedyThought;

public class isSubsequence {
    public boolean isSubsequence(String s, String t) {
        if (s == null || t == null) return false;
        int lengthS = s.length();
        int lengthT = t.length();
        for (int i = 0, j = 0; i < lengthS && j < lengthT;) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
                j++;
            } else {
                j++;
            }
            if (i == lengthS) {
                return true;
            }
        }
        return false;
    }

    public boolean isSubsequenceI(String s, String t) {
        int index = -1;
        for (char c: s.toCharArray()) {
            index = t.indexOf(c, index + 1);
            if (index == -1) {
                return false;
            }
        }
        return true;
    }
}
